#!/bin/bash
# 版本 注意，打包时包名与版本后缀一致
version="0.0.1"
code_path="/opt/resource/jldy_jy-jldzjy-api"
# 运行目录
run_path="/opt/lt-meeting/"
# JDK目录
export JAVA_HOME="/opt/lt-meeting/jdk17"
export PATH="$JAVA_HOME/bin:$PATH"
echo "开始..."
cd "${code_path}" || exit 1  # 进入代码目录，如果失败则退出
echo "进入$(pwd)，正在获取最新的代码..."
git checkout -f prod
git pull
echo "停止现有的Java进程..."
ps -ef | grep java | grep api-manage | grep -v 'grep' | awk '{print $2}' | xargs kill -9
echo "清理现有的JAR文件..."
sudo rm -rf "${run_path}api-manage*.jar"
echo "构建项目中..."
mvn clean install -DskipTests  # 使用系统中的 Maven
echo "将JAR文件移至运行目录..."
sudo mv "${code_path}/api-manage/target/api-manage-${version}.jar" "${run_path}"
echo "启动Java进程中..."
cd "${run_path}" || exit 1  # 进入运行目录，如果失败则退出
nohup java -Xmx2048m -Xms2048m -Xss2000k -jar "${run_path}api-manage-${version}.jar" --spring.profiles.active=prod > /dev/null 2>&1 &
echo "Java进程已成功启动。"
echo "查看日志文件..."
tail -f "${run_path}logs/api-manage.log"
